//
//  HZMDetailsCVCell.m
//  糖糖大魔王
//
//  Created by 韩震明 on 15/10/27.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "HZMDetailsCVCell.h"
#define WIDTH self.backView.frame.size.width
#define HEIGHT self.backView.frame.size.height

@implementation HZMDetailsCVCell

- (void)dealloc
{
    [_numberLabel release];
    [_titleLabel release];
    [_descLabel release];
    [_picImageViewHead release];
    [_picImageViewFoot release];
    [_commentImageView release];
    [_commentLabel release];
    [_likesButton release];
    [_likesLabel release];
    [_buyButton release];
    [_priceImageView release];
    [_priceLabel release];
    [_backView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)createCell
{
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
    [self.contentView addSubview:self.backView];
    [_backView release];
//    self.backView.layer.borderWidth = 1;
//    self.backView.layer.cornerRadius = 5;
//    self.backView.layer.borderColor = [[UIColor grayColor] CGColor];
    
    self.numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 140, HEIGHT / 400, WIDTH / 20, HEIGHT / 50)];
    [self.backView addSubview:self.numberLabel];
    [_numberLabel release];
    self.numberLabel.layer.borderWidth = 1;
    self.numberLabel.layer.borderColor = [[UIColor redColor] CGColor];
    self.numberLabel.textAlignment = NSTextAlignmentCenter;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 17, HEIGHT / 300, WIDTH - 20, HEIGHT / 50)];
    [self.backView addSubview:self.titleLabel];
    [_titleLabel release];
    self.titleLabel.font = [UIFont systemFontOfSize:18.0];
    self.titleLabel.numberOfLines = 0;
    
    self.descLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 140, HEIGHT / 25, WIDTH - 20, HEIGHT / 9)];
    [self.backView addSubview:self.descLabel];
    [_descLabel release];
    self.descLabel.font = [UIFont systemFontOfSize:14.0];
    self.descLabel.numberOfLines = 0;
    self.descLabel.textColor = [UIColor grayColor];
    
    self.picImageViewHead = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 140, HEIGHT / 4, WIDTH - 6, HEIGHT / 3)];
    [self.backView addSubview:self.picImageViewHead];
    [_picImageViewHead release];
    
//    self.picImageViewFoot = [[UIImageView alloc] init];
//    [self.backView addSubview:self.picImageViewFoot];
//    [_picImageViewFoot release];
    
    self.priceImageView = [[UIImageView alloc] initWithFrame:CGRectMake(12 * WIDTH / 18, 6 * HEIGHT / 10, 30, HEIGHT / 30)];
    [self.backView addSubview:self.priceImageView];
    [_priceImageView release];
    self.priceImageView.image = [UIImage imageNamed:@"Card.png"];
    
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(7 * WIDTH / 9, 6 * HEIGHT / 10, WIDTH / 8, HEIGHT / 30)];
    [self.backView addSubview:self.priceLabel];
    [_priceLabel release];
    
    self.commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(2 * WIDTH / 9, 7 * HEIGHT / 10, WIDTH / 10, HEIGHT / 25)];
    [self.backView addSubview:self.commentLabel];
    [_commentLabel release];
    
    self.commentImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 9, 7 * HEIGHT / 10, WIDTH / 10, HEIGHT / 25)];
    [self.backView addSubview:self.commentImageView];
    [_commentImageView release];
    self.commentImageView.image = [UIImage imageNamed:@"comment.png"];
    
    self.likesLabel = [[UILabel alloc] initWithFrame:CGRectMake(2 * WIDTH / 9, 8 * HEIGHT / 10, WIDTH / 5, HEIGHT / 25)];
    [self.backView addSubview:self.likesLabel];
    [_likesLabel release];
    
//    self.likesImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 9, 8 * HEIGHT / 10, WIDTH / 10, HEIGHT / 25)];
//    [self.backView addSubview:self.likesImageView];
//    [_likesImageView release];
//    self.likesImageView.image = [UIImage imageNamed:@"No_Attention.png"];
//    self.likesImageView.userInteractionEnabled = YES;
    
    self.buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.backView addSubview:self.buyButton];
    self.buyButton.frame = CGRectMake(4 * WIDTH / 10, 9 * HEIGHT / 12, 2 * WIDTH / 5, HEIGHT / 15);
    [self.buyButton setTitle:@"购买" forState:UIControlStateNormal];
    self.buyButton.layer.borderWidth = 1;
    self.buyButton.layer.cornerRadius = 15;
    [self.buyButton setImage:[UIImage imageNamed:@"buy_car"] forState:UIControlStateNormal];
    [self.buyButton addTarget:self action:@selector(cellbtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)cellbtnClick:(UIButton *)buyButton
{
    self.takeModel(self.buyButton.tag - 100000);
}

@end
